<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">
  <link rel="alternate" href="/blog/atom.xml" title="愿被世界温柔以待" type="application/atom+xml">

<link rel="stylesheet" href="/blog/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Monda:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/blog/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://skyperfect.gitee.io/blog').hostname,
    root: '/blog/',
    scheme: 'Mist',
    version: '7.5.0',
    exturl: false,
    sidebar: {"position":"left","display":"post","offset":12,"onmobile":false},
    copycode: {"enable":false,"show_result":false,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: '',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    sidebarPadding: 40
  };
</script>

  <meta name="description" content="[TOC]引用 引用就是某一变量（目标）的一个别名，对引用的操作与对变量的直接操作完全一样 12int a;int &amp;amp;ra=a; &#x2F;&#x2F;定义引用ra，它是变量a的引用，即别名注意以下几点 &amp;amp;在此处不是取地址运算，而是标识作用。 声明引用时，必须对其进行初始化。 引用声明完毕后，相当于目标变量名有两个名称，即该目标原名称和引用名，且不能再把该引用名作为其他变量的别名。 声明一个引用，不">
<meta property="og:type" content="article">
<meta property="og:title" content="C++学习">
<meta property="og:url" content="https:&#x2F;&#x2F;skyperfect.gitee.io&#x2F;blog&#x2F;2019&#x2F;11&#x2F;24&#x2F;Cplus%E5%AD%A6%E4%B9%A0&#x2F;index.html">
<meta property="og:site_name" content="愿被世界温柔以待">
<meta property="og:description" content="[TOC]引用 引用就是某一变量（目标）的一个别名，对引用的操作与对变量的直接操作完全一样 12int a;int &amp;amp;ra=a; &#x2F;&#x2F;定义引用ra，它是变量a的引用，即别名注意以下几点 &amp;amp;在此处不是取地址运算，而是标识作用。 声明引用时，必须对其进行初始化。 引用声明完毕后，相当于目标变量名有两个名称，即该目标原名称和引用名，且不能再把该引用名作为其他变量的别名。 声明一个引用，不">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http:&#x2F;&#x2F;q274vi0py.bkt.clouddn.com&#x2F;cplus.jpg">
<meta property="og:updated_time" content="2019-12-08T13:56:04.532Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http:&#x2F;&#x2F;q274vi0py.bkt.clouddn.com&#x2F;cplus.jpg">

<link rel="canonical" href="https://skyperfect.gitee.io/blog/2019/11/24/Cplus%E5%AD%A6%E4%B9%A0/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true,
    isPage: false,
    isArchive: false
  };
</script>

  <title>C++学习 | 愿被世界温柔以待</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">愿被世界温柔以待</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/blog/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/blog/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
        <li class="menu-item menu-item-schedule">

    <a href="/blog/schedule/" rel="section"><i class="fa fa-fw fa-calendar"></i>日程表</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/skyie" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://skyperfect.gitee.io/blog/blog/2019/11/24/Cplus%E5%AD%A6%E4%B9%A0/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="brayden">
      <meta itemprop="description" content="记录工作，记录生活">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="愿被世界温柔以待">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          C++学习
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-11-24 21:06:04" itemprop="dateCreated datePublished" datetime="2019-11-24T21:06:04+08:00">2019-11-24</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-12-08 21:56:04" itemprop="dateModified" datetime="2019-12-08T21:56:04+08:00">2019-12-08</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index">
                    <span itemprop="name">编程基础</span>
                  </a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>[TOC]</p><p><img src="http://q274vi0py.bkt.clouddn.com/cplus.jpg" alt></p><h2 id="引用"><a href="#引用" class="headerlink" title="引用"></a>引用</h2><p> 引用就是某一变量（目标）的一个别名，对引用的操作与对变量的直接操作完全一样 </p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">int a;</span><br><span class="line">int &amp;ra=a; //定义引用ra，它是变量a的引用，即别名</span><br></pre></td></tr></table></figure><p>注意以下几点</p><ul>
<li>&amp;在此处不是取地址运算，而是标识作用。</li>
<li>声明引用时，必须对其进行初始化。</li>
<li>引用声明完毕后，相当于目标变量名有两个名称，即该目标原名称和引用名，且不能再把该引用名作为其他变量的别名。</li>
<li>声明一个引用，不是新定义了一个变量，它只表示该引用名是目标变量名的一个别名，他本身不是一种数据类型，因此引用本身不占存储单元，系统也不给引用分配存储单元。因此对引用求地址，就是对目标变量求地址。</li>
<li>不能建立数组的引用，因为数组是一个由若干个元素组成的集合，所以无法建立一个数组的别名。</li>
</ul><a id="more"></a>






<h2 id="类型转换"><a href="#类型转换" class="headerlink" title="类型转换"></a>类型转换</h2><p> 在C/C++中有以下四种情况会发生自动类型转换 </p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;iostream&gt;</span><br><span class="line">#include &lt;stdlib.h&gt;</span><br><span class="line">#include &lt;string.h&gt;</span><br><span class="line"></span><br><span class="line">using namespace std;</span><br><span class="line"></span><br><span class="line">int add(double  num1,double num2)</span><br><span class="line">&#123;</span><br><span class="line">    return  num1+num2;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line">    //第1种：赋值</span><br><span class="line">    int i = 3.14;   //转换成int型</span><br><span class="line">    cout &lt;&lt; &quot;i=&quot; &lt;&lt; i &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">    //第2种：运算时</span><br><span class="line">    double res = 4 + 3.14;  //4运算前转换成double型</span><br><span class="line">    cout &lt;&lt; &quot;res=&quot; &lt;&lt; res &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">    //第3种: 函数调用实参与形参不一致时，自动转换成形参类型</span><br><span class="line">    //第4种：当返回值类型与函数返回类型不一致时,自动转换成函数返回类型</span><br><span class="line">    int result = add(2,3);  //2,3转换成double型,5再转换成int型</span><br><span class="line">    cout &lt;&lt; &quot;result=&quot; &lt;&lt; result &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">    return  0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="命名空间"><a href="#命名空间" class="headerlink" title="命名空间"></a>命名空间</h2><p> C++中使用命名空间来解决在相同文件或范围的同名变量问题，示例如下：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">#include &lt;iostream&gt;</span><br><span class="line">using namespace std;</span><br><span class="line"></span><br><span class="line">namespace schoolname   //定义命名空间schoolname</span><br><span class="line">&#123;</span><br><span class="line">    const char *name = &quot;Xiaoming&quot;;  </span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">namespace homename   //定义命名空间homename</span><br><span class="line">&#123;</span><br><span class="line">    const char *name = &quot;Lily&quot;;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">int main()</span><br><span class="line">&#123;</span><br><span class="line">    cout &lt;&lt; &quot;school : &quot; &lt;&lt; schoolname::name &lt;&lt; endl;   //访问schoolname命名空间中的数据</span><br><span class="line">    cout &lt;&lt; &quot;homename : &quot; &lt;&lt; homename::name &lt;&lt; endl;   //访问homename命名空间中的数据</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p> C++的所有标识符都被定义在一个名叫std的namespace，有以下几种使用方法</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">// 第1种直接声明使用    </span><br><span class="line">std::cout&lt;&lt;&quot;hello world&quot;&lt;&lt;std::endl;</span><br><span class="line"> </span><br><span class="line">//第2种:先用using声明要使用的标识符</span><br><span class="line">using std::cout;</span><br><span class="line">using std::endl;</span><br><span class="line">cout &lt;&lt; &quot;hello world&quot; &lt;&lt; endl;</span><br><span class="line"></span><br><span class="line">//第3种:声明使用标准命名空间中所有内容(即标识符)</span><br><span class="line">using namespace std;    //一般申明在头文件后</span><br><span class="line">cout&lt;&lt;&quot;hello world&quot;&lt;&lt;endl;</span><br></pre></td></tr></table></figure>



<h2 id="内存管理"><a href="#内存管理" class="headerlink" title="内存管理"></a>内存管理</h2><h3 id="new-delete与malloc-free比较"><a href="#new-delete与malloc-free比较" class="headerlink" title="new/delete与malloc/free比较"></a>new/delete与malloc/free比较</h3><p>malloc 与 free 是 C++/C 语言的标准库函数，new/delete 是 C++ 的运算符 。</p>
<p>对象在创建的同时要自动执行构造函数，对象在消亡之前要自动执行析构函数。由于 malloc/free 是库函数而不是运算符，不在编译器控制权限之内，不能够把执行构造函数和析构函数的任务强加于 malloc/free 。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">class Obj</span><br><span class="line">&#123;</span><br><span class="line">public :</span><br><span class="line">    Obj(void) &#123; cout &lt;&lt; “initialization” &lt;&lt; endl; &#125;</span><br><span class="line">    ~Obj (void) &#123; cout &lt;&lt; “destroy” &lt;&lt; endl; &#125;</span><br><span class="line">    void initialize(void)&#123; cout &lt;&lt; “initialization” &lt;&lt; endl; &#125;</span><br><span class="line">    void destroy(void)&#123; cout &lt;&lt; “destroy” &lt;&lt; endl; &#125;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line">// C风格的需要分配内存后调用初始化，在释放内存前调用清除</span><br><span class="line">void useMallocFree(void)</span><br><span class="line">&#123;</span><br><span class="line">    Obj *a = (obj *)malloc(sizeof(obj)); // 申请动态内存</span><br><span class="line">    a-&gt;initialize(); // 初始化</span><br><span class="line">    //…</span><br><span class="line">    a-&gt;destroy(); // 清除工作</span><br><span class="line">    free(a); // 释放内存</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">//C++ 只需要调用new，自动调用构造函数，delete自动调用析构函数</span><br><span class="line">void useNewDelete(void)</span><br><span class="line">&#123;</span><br><span class="line">    Obj *a = new Obj; // 申请动态内存并且初始化</span><br><span class="line">    //…</span><br><span class="line">    delete a; // 清除并且释放内存</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="类占用的空间大小"><a href="#类占用的空间大小" class="headerlink" title="类占用的空间大小"></a>类占用的空间大小</h3><p><strong>空类</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">class Obj</span><br><span class="line">&#123; </span><br><span class="line">&#125;; </span><br><span class="line">sizeof(Obj) = 1;</span><br></pre></td></tr></table></figure>

<p> c++要求每个实例在内存中都有独一无二的地址。空类也会被实例化，所以编译器会给空类隐含的添加一个字节，这样空类实例化之后就有了独一无二的地址了。所以空类的 sizeof 为 1。 </p>
<p><strong>对齐</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">class Obj</span><br><span class="line">&#123; </span><br><span class="line">    int a; </span><br><span class="line">    char p; </span><br><span class="line">&#125;; </span><br><span class="line">sizeof(Obj) = 8;</span><br></pre></td></tr></table></figure>

<p> int 占 4 字节，char 占一字节，补齐 3 字节 ,一共8字节</p>
<h2 id="对象，继承，多态"><a href="#对象，继承，多态" class="headerlink" title="对象，继承，多态"></a>对象，继承，多态</h2><h2 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h2><h2 id="容器"><a href="#容器" class="headerlink" title="容器"></a>容器</h2><p>STL提供包含 容器、迭代器和算法三个部分 。</p>
<ul>
<li><strong>容器</strong>（Containers）：用来管理某类对象的集合。每一种容器都有其优点和缺点，所以，为了应付程序中的不同需求，STL 准备了七种基本容器类型。</li>
<li><strong>迭代器</strong>（Iterators）：用来在一个对象集合的元素上进行遍历动作。这个对象集合或许是个容器，或许是容器的一部分。每一种容器都提供了自己的迭代器，而这些迭代器了解该种容器的内部结构。</li>
<li><strong>算法</strong>（Algorithms）：用来处理对象集合中的元素，比如 Sort，Search，Copy，Erase 那些元素。通过迭代器的协助，我们只需撰写一次算法，就可以将它应用于任意容器之上，这是因为所有容器的迭代器都提供一致的接口。</li>
</ul>
<p>STL 的基本观念就是将数据和操作分离。数据由容器进行管理，操作则由算法进行，而迭代器在两者之间充当粘合剂，使任何算法都可以和任何容器交互运作</p>
<h3 id="vector"><a href="#vector" class="headerlink" title="vector"></a>vector</h3><p>和数组差不多，但它比数组要好。数组不能动态拓展，程序运行的时候不是浪费内存，就是造成越界 。在元素个数不够时，会自动扩大元素个数。</p>
<p>优点：支持随机访问，所以查询效率高 </p>
<p>缺点：当向其头部或中部插入或删除元素时，为了保持原本的相对次序，插入或删除点之后的所有元素都必须移动，所以插入的效率比较低 </p>
<p>适用场景：</p>
<p>适用于对象变化较小，频繁访问的场景。</p>
<h3 id="deque-double-ended-queue"><a href="#deque-double-ended-queue" class="headerlink" title="deque (double-ended queue)"></a>deque (double-ended queue)</h3><p> 适用场景：</p>
<p>适用于既要频繁随机存取，又要关心两端数据的插入与删除的场景。 </p>
<h3 id="list-doubly-linked-list"><a href="#list-doubly-linked-list" class="headerlink" title="list( doubly linked list )"></a>list( doubly linked list )</h3><p>双向链表实现，内存空间不连续。</p>
<p>优点：内存不连续，动态操作，可在任意位置插入或删除且效率高。</p>
<p>缺点：不支持随机访问。</p>
<p>适用场景：适用于经常进行插入和删除操作并且不经常随机访问的场景。 </p>
<h3 id="set"><a href="#set" class="headerlink" title="set"></a>set</h3><p> set（集合）由红黑树实现，其内部元素依据其值自动排序，每个元素值只能出现一次，不允许重复 </p>
<p>特点：有序，不重复</p>
<p>优点：使用平衡二叉树实现，便于元素查找，且保持了元素的唯一性，以及能自动排序。</p>
<p>缺点：每次插入值的时候，都需要调整红黑树，效率有一定影响。</p>
<p>适用场景：适用于经常查找一个元素是否在某群集中且需要排序的场景。 </p>
<h3 id="multiset"><a href="#multiset" class="headerlink" title="multiset"></a>multiset</h3><h3 id="map"><a href="#map" class="headerlink" title="map"></a>map</h3><h3 id="multimap"><a href="#multimap" class="headerlink" title="multimap"></a>multimap</h3><h2 id="C-11新特性"><a href="#C-11新特性" class="headerlink" title="C++11新特性"></a>C++11新特性</h2><h3 id="智能指针"><a href="#智能指针" class="headerlink" title="智能指针"></a>智能指针</h3>
    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2019/11/24/IDE%E5%A4%A7%E5%85%A8/" rel="prev" title="IDE笔记">
      <i class="fa fa-chevron-left"></i> IDE笔记
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2019/11/24/python%E8%AF%AD%E6%B3%95%E5%AD%A6%E4%B9%A0/" rel="next" title="python语法学习">
      python语法学习 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#引用"><span class="nav-number">1.</span> <span class="nav-text">引用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#类型转换"><span class="nav-number">2.</span> <span class="nav-text">类型转换</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#命名空间"><span class="nav-number">3.</span> <span class="nav-text">命名空间</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#内存管理"><span class="nav-number">4.</span> <span class="nav-text">内存管理</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#new-delete与malloc-free比较"><span class="nav-number">4.1.</span> <span class="nav-text">new/delete与malloc/free比较</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#类占用的空间大小"><span class="nav-number">4.2.</span> <span class="nav-text">类占用的空间大小</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#对象，继承，多态"><span class="nav-number">5.</span> <span class="nav-text">对象，继承，多态</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#字符串"><span class="nav-number">6.</span> <span class="nav-text">字符串</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#容器"><span class="nav-number">7.</span> <span class="nav-text">容器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#vector"><span class="nav-number">7.1.</span> <span class="nav-text">vector</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#deque-double-ended-queue"><span class="nav-number">7.2.</span> <span class="nav-text">deque (double-ended queue)</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#list-doubly-linked-list"><span class="nav-number">7.3.</span> <span class="nav-text">list( doubly linked list )</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#set"><span class="nav-number">7.4.</span> <span class="nav-text">set</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#multiset"><span class="nav-number">7.5.</span> <span class="nav-text">multiset</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#map"><span class="nav-number">7.6.</span> <span class="nav-text">map</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#multimap"><span class="nav-number">7.7.</span> <span class="nav-text">multimap</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#C-11新特性"><span class="nav-number">8.</span> <span class="nav-text">C++11新特性</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#智能指针"><span class="nav-number">8.1.</span> <span class="nav-text">智能指针</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">brayden</p>
  <div class="site-description" itemprop="description">记录工作，记录生活</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">12</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/blog/categories/">
          
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
  </nav>
</div>
  <div class="feed-link motion-element">
    <a href="/blog/atom.xml" rel="alternate">
      <i class="fa fa-rss"></i>RSS
    </a>
  </div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/skyie" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;skyie" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">brayden</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> v7.5.0
  </div>

        








        
      </div>
    </footer>
  </div>

  
  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="/blog/lib/canvas-nest/canvas-nest.min.js"></script>
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>
<script src="/blog/js/utils.js"></script><script src="/blog/js/motion.js"></script>
<script src="/blog/js/schemes/muse.js"></script>
<script src="/blog/js/next-boot.js"></script>



  
















  

  

</body>
</html>
